require 'erb'

before "deploy:setup", :webapp_config
after "deploy:update_code", "webapp_config:symlink" 

namespace :webapp_config do
  desc "Create webapp config yaml in shared path" 
  task :default do
    webapp_config = ERB.new <<-EOF
    defaults: &defaults
      host: #{host}
      facebook_client_id: #{facebook_app_id}
      facebook_secret: #{fb_secret_key}
      facebook_key: #{fb_api_key}
      facebook_canvas: #{fb_canvas_name}
      default_game_image: pencil.png
      emails:
       info_from: info@thewebdawn.net
      smtp_settings:
        address: smtp1.servage.net
        port: 25
        domain: thewebdawn.net
        user_name: info@thewebdawn.net
        password: Planta098=)(

    development:
      <<: *defaults
    test:
      <<: *defaults
    production:
      <<: *defaults
    EOF

    run "mkdir -p #{shared_path}/config" 
    put webapp_config.result, "#{shared_path}/config/webapp_config.yml" 
  end

  desc "Make symlink for webapp config yaml" 
  task :symlink do
    run "ln -nfs #{shared_path}/config/webapp_config.yml #{release_path}/config/webapp_config.yml" 
  end
end
